From: Jasper St. Pierre Date: Sun, 30 Dec 2012 16:45:43 +0000 (-0500) Subject: notificationDaemon: Merge two pieces of similar code X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~5132 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=1bd349485f8fc8b45715367ea53f8161b03f690d;p=gnome-shell.git notificationDaemon: Merge two pieces of similar code Use the same code for parsing notification data to handle both icons and images. https://bugzilla.gnome.org/show_bug.cgi?id=680414 --- diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index 1b24883b0..295024c06 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -127,6 +127,18 @@ const NotificationDaemon = new Lang.Class({ this._trayManager.manage_stage(global.stage, Main.messageTray.actor); }, + _imageForNotificationData: function(hints) { + if (hints['image-data']) { + let [width, height, rowStride, hasAlpha, + bitsPerSample, nChannels, data] = hints['image-data']; + return Shell.util_create_pixbuf_from_data(data, GdkPixbuf.Colorspace.RGB, hasAlpha, + bitsPerSample, width, height, rowStride); + } else if (hints['image-path']) { + return new Gio.FileIcon({ file: Gio.File.new_for_path(hints['image-path']) }); + } + return null; + }, + _iconForNotificationData: function(icon, hints) { // If an icon is not specified, we use 'image-data' or 'image-path' hint for an icon // and don't show a large image. There are currently many applications that use @@ -143,13 +155,8 @@ const NotificationDaemon = new Lang.Class({ return new Gio.FileIcon({ file: Gio.File.new_for_path(icon) }); else return new Gio.ThemedIcon({ name: icon }); - } else if (hints['image-data']) { - let [width, height, rowStride, hasAlpha, - bitsPerSample, nChannels, data] = hints['image-data']; - return Shell.util_create_pixbuf_from_data(data, GdkPixbuf.Colorspace.RGB, hasAlpha, - bitsPerSample, width, height, rowStride); - } else if (hints['image-path']) { - return new Gio.FileIcon({ file: Gio.File.new_for_path(hints['image-path']) }); + } else if (hints['image-data'] || hints['image-path']) { + return this._imageForNotificationData(hints); } else { let stockIcon; switch (hints.urgency) { @@ -388,19 +395,11 @@ const NotificationDaemon = new Lang.Class({ clear: true }); // We only display a large image if an icon is also specified. - let image = null; - if (icon && (hints['image-data'] || hints['image-path'])) { - if (hints['image-data']) { - let [width, height, rowStride, hasAlpha, - bitsPerSample, nChannels, data] = hints['image-data']; - image = St.TextureCache.get_default().load_from_raw(data, hasAlpha, - width, height, rowStride, notification.IMAGE_SIZE); - } else if (hints['image-path']) { - image = St.TextureCache.get_default().load_uri_async(GLib.filename_to_uri(hints['image-path'], null), - notification.IMAGE_SIZE, - notification.IMAGE_SIZE); - } - } + let image; + if (icon && (hints['image-data'] || hints['image-path'])) + image = new St.Icon({ gicon: this._imageForNotificationData(hints) }); + else + image = null; notification.setImage(image); if (actions.length) {